package com.cnware.capture.ui.view.navigator.resource;

import java.util.ArrayList;

import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.swt.graphics.Image;

import com.cnware.capture.model.Project;
import com.cnware.capture.model.Workspace;
import com.cnware.capture.ui.view.navigator.NavigatorItem;

public class RootItem extends PlatformObject implements NavigatorItem{
	
	private Workspace workspace;
	
	private ArrayList<NavigatorItem> project;

	public RootItem() {
		this.workspace = new Workspace();
	}
	
	@Override
	public Object[] getChildren() {
		if(project == null || project.size() != workspace.getProjectList().size()){
			project = new ArrayList<NavigatorItem>();
			ArrayList<Project> projectList = workspace.getProjectList();
			for(Project proj : projectList){
				ProjectItem projectItem = new ProjectItem(proj);
				projectItem.setParent(this);
				project.add(projectItem);
			}
		}
		return project.toArray(new Object[project.size()]);
	}

	@Override
	public Object getParent() {
		return null;
	}

	@Override
	public boolean hasChildred() {
		return workspace.getProjectList().size()>0;
	}

	@Override
	public void setParent(NavigatorItem item) {
		
	}

	@Override
	public String getText() {
		return this.workspace.getWorkForder();
	}

	@Override
	public Image getImage() {
		return null;
	}
	
	

}
